﻿-- =============================================
-- Author:		Sandy Stewart, Fujitsu
-- Create date: 02/07/2011
-- Description:	Update command for ParliamentarianLinks entity
-- =============================================
-- Version Date: 29/09/2011, CR06
-- Update for additional editable fields
-- =============================================
CREATE PROCEDURE [dbo].[UpdateParliamentarianLink] 
	-- Add the parameters for the stored procedure here
	@CPALId int,
	@PartyWebsite varchar(100),
	@PersonalWebsite varchar(100),
	@FacebookAddress varchar(100),
	@TwitterAddress varchar(100),
	@EmailVisible bit,
	@ContactFormVisible bit,
	@Link1Label varchar(200),
	@Link1Address varchar(200),
	@Link2Label varchar(200),
	@Link2Address varchar(200),
	@Link3Label varchar(200),
	@Link3Address varchar(200),
	@Link4Label varchar(200),
	@Link4Address varchar(200),
	@Link5Label varchar(200),
	@Link5Address varchar(200),
	@ElectionMessage varchar(max),
	@FirstSpeechLink varchar(200),
	@ShortURL varchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF (SELECT COUNT(*) FROM ParliamentarianWebLinks WHERE CPALId = @CPALId) = 0
		BEGIN
			INSERT INTO ParliamentarianWebLinks
				(	CPALId,
					PartyWebsite,
					PersonalWebsite,
					FacebookAddress,
					TwitterAddress,
					EmailVisible,
					ContactFormVisible,
					Link1Label,
					Link1Address,
					Link2Label,
					Link2Address,
					Link3Label,
					Link3Address,
					Link4Label,
					Link4Address,
					Link5Label,
					Link5Address,
					ElectionMessage,
					FirstSpeechLink,
					ShortURL)
			VALUES
				(	@CPALId,
					@PartyWebsite,
					@PersonalWebsite,
					@FacebookAddress,
					@TwitterAddress,
					@EmailVisible,
					@ContactFormVisible,
					@Link1Label,
					@Link1Address,
					@Link2Label,
					@Link2Address,
					@Link3Label,
					@Link3Address,
					@Link4Label,
					@Link4Address,
					@Link5Label,
					@Link5Address,
					@ElectionMessage,
					@FirstSpeechLink,
					@ShortURL)
		END
	ELSE
		BEGIN
			-- Update ParliamentarianWebLinks table
			UPDATE ParliamentarianWebLinks
			SET PartyWebsite = @PartyWebsite,
				PersonalWebsite = @PersonalWebsite,
				FacebookAddress = @FacebookAddress,
				TwitterAddress = @TwitterAddress,
				EmailVisible = @EmailVisible,
				ContactFormVisible = @ContactFormVisible,
				Link1Label =	@Link1Label,
				Link1Address = 	@Link1Address,
				Link2Label = 	@Link2Label,
				Link2Address =	@Link2Address,
				Link3Label = 	@Link3Label,
				Link3Address =	@Link3Address,
				Link4Label =	@Link4Label,
				Link4Address = 	@Link4Address,
				Link5Label =	@Link5Label,
				Link5Address =	@Link5Address,
				ElectionMessage =	@ElectionMessage,
				FirstSpeechLink =	@FirstSpeechLink,
				ShortURL =			@ShortURL
			WHERE CPALId = @CPALId
		END		

END